package com.iss.apartmentmanage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iss.apartmentmanage.entity.Reserve;
import com.iss.apartmentmanage.mapper.ReserveMapper;
import com.iss.apartmentmanage.service.ReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class ReserveServiceImpl implements ReserveService {
    @Autowired
    ReserveMapper reserveMapper;

    /**
     * 查询全部的预定信息
     * @param pageNum
     * @param pageSize
     * @param reserve
     * @return
     */
    @Override
    public IPage<Reserve> selectAllReserveMessage(int pageNum, int pageSize,Reserve reserve) {
        Page page = new Page(pageNum,pageSize);
        QueryWrapper<Reserve> wrapper = new QueryWrapper<>();
        if(reserve.getReserveName()!=null || reserve.getReservePhone()!=null){
            wrapper.like("reserve_name",reserve.getReserveName()).or().like("reserve_phone",reserve.getReservePhone());
        }

        IPage<Reserve> iPage = reserveMapper.selectPage(page,wrapper);
        return iPage;
    }

    /**
     * 添加预定信息，客户从前端进行预定
     * @param reserve
     * @return
     */
    @Override
    public Integer insertReserve(Reserve reserve) {
        int count = 0 ;
        try{
            if(reserve!=null){
                count = reserveMapper.insert(reserve);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }
    /**
     * 添加预定信息，客户从前端进行预定
     * @param reserve
     * @return
     */
    @Override
    public Integer updateReserve(Reserve reserve) {
        int count = 0 ;
        try{
            if(reserve!=null){
                count = reserveMapper.updateById(reserve);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }
    /**
     * 添加预定信息，客户从前端进行预定
     * @param reserveId
     * @return
     */
    @Override
    public Integer deleteReserve(Integer reserveId) {
        int count = 0 ;
        try{
            if(reserveId!=null){
                count = reserveMapper.deleteById(reserveId);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }


















}
